﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data;
using KPIS.GERP.GHRMS.IDAL;
using KPIS.GERP.GHRMS.MODEL;
using KPIS.GERP.GHRMS.DALFactory;
using KPIS.GERP.GHRMS.IBLL;

namespace KPIS.GERP.GHRMS.BLL
{
    public class MasAmphurBLL : IMasAmphurBLL
    {
        private static readonly IMasAmphurDAL dal = DataAccess.CreateMasterAmphurs();

        private MasAmphurInfo ampInfo = new MasAmphurInfo();
        private MasProvinceInfo provInfo = new MasProvinceInfo();
        public IList<MasAmphurInfo> ListAmphurs()
        {
            return dal.ListAmphurs(new MasAmphurInfo(0));
        }
        public IList<MasAmphurInfo> ListAmphurs(string Sequence, string Province)
        {
            provInfo.Sequence = Province.Length > 0 ? Int32.Parse(Province) : 0;
            ampInfo.Sequence = Sequence.Length > 0 ? Int32.Parse(Sequence) : 0;
            ampInfo.Provinces = provInfo;

            return dal.ListAmphurs(ampInfo);
        }
        public void Insert(string Name, string NameEng, int Province, Nullable<int> CreatedBy)
        {
            provInfo.Sequence = Province;

            try
            {
                dal.Insert(new MasAmphurInfo(0, Name, NameEng, provInfo, CreatedBy, 0));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Update(int Sequence, string Name, string NameEng, int Province, Nullable<int> UpdatedBy)
        {
            provInfo.Sequence = Province;

            try
            {
                dal.Update(new MasAmphurInfo(Sequence, Name, NameEng, provInfo, 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
        public void Delete(int Sequence, Nullable<int> UpdatedBy)
        {
            try
            {
                dal.Delete(new MasAmphurInfo(Sequence, "", "", provInfo, 0, UpdatedBy));
            }
            catch
            {
                throw new Exception("");
            }
        }
    }
}
